
class Output(object):
                
    def __init__(self, log=False):
        self.__listeners = []
        self.__log = log
        self.__last_log = None
        self.__repeat = False
        self.__count = 0
        
    def send(self, out):
        for listener in self.__listeners:
            listener.handle(out)
        if(self.__log):
            if(self.__last_log == out):
                self.__count += 1
                if(not self.__repeat):
                    self.__repeat = True
                    print "+"
            else:
                if(self.__repeat):
                    print(self.__last_log + " x " +  str(self.__count))
                    self.__repeat = False
                    self.__count = 0
                    
                self.__last_log = out
                print out
        
    def add_listener(self, listener):
        self.__listeners.append(listener)